﻿@using Microsoft.AspNetCore.Components.Web;
@using Microsoft.JSInterop;
@using ThingsGateway.Core.Json.Extension
@using ThingsGateway.Extension
@using ThingsGateway.Foundation
@using BootstrapBlazor.Components
@namespace ThingsGateway.Debug
@inherits AdapterDebugBase

<div class=@($"{ClassString} row my-2 mx-2") style="min-height:500px;height: 50%;">

    <div class="col-12 col-md-5 h-100">
        <Tab class="h-100">
            <TabItem Text=@Localizer["CommonFunctions"]>
                @if (ShowDefaultReadWriteContent)
                {

                    <BootstrapInput title=@Plc?.GetAddressDescription() @bind-Value=@RegisterAddress
                                    ShowLabel="true" style="width:100%" />


                    <div class="row mx-1 form-inline mt-2">

                        <div class="col-12 col-md-8 p-1">

                            <div class="p-1">

                                <BootstrapInputNumber @bind-Value=@ArrayLength ShowLabel="true" />
                                <Select @bind-Value="@DataType" ShowLabel="true"  IsPopover="true"/>
                            </div>

                        </div>
                        <div class="col-12 col-md-4 p-1">

                            <Button IsAsync Color="Color.Primary" OnClick="ReadAsync">@Localizer["Read"]</Button>

                        </div>

                    </div>

                    <Divider />

                    <div class="row mx-1 form-inline mt-2">

                        <div class="col-12 col-md-8 p-1">
                            <Textarea @bind-Value=@WriteValue ShowLabelTooltip="true"
                                      ShowLabel="true" />

                        </div>
                        <div class="col-12 col-md-4 p-1">
                            <Button IsAsync Color="Color.Primary" OnClick="WriteAsync">@Localizer["Write"]</Button>
                        </div>
                    </div>


                }
                @if (ReadWriteContent != null)
                {
                    @ReadWriteContent
                }
            </TabItem>


            <TabItem Text=@Localizer["SpecialFunctions"]>
                @if (ShowDefaultOtherContent)
                {

                    @foreach (var item in VariableRunTimes)
                    {

                        <div class="row mx-1 form-inline mt-2">

                            <div class="col-12 col-md-8 p-1">

                                <div class="p-1">

                                    <BootstrapInput @bind-Value=@item.RegisterAddress title="@Plc?.GetAddressDescription()"
                                                    ShowLabel="true" style="width:100%" />

                                    <Select @bind-Value="@item.DataType" ShowLabel="true" IsPopover />
                                </div>

                            </div>
                            <div class="col-12 col-md-4 p-1">

                                <div title=@(item.LastErrorMessage) class=@(item.IsOnline?"green--text":"red--text")>@(item.Value?.ToJsonNetString())</div>

                            </div>
                        </div>

                    }



                    <Divider />


                    <Button IsAsync Color="Color.Primary" OnClick="MulRead">@Localizer["MulRead"]</Button>


                }

            </TabItem>

        </Tab>

    </div>
    <div class="col-12 col-md-7 ">
        @if (Plc?.Logger != null || Logger!=null)
        {
            <LogConsole LogLevel=@((Plc?.Logger??Logger).LogLevel) LogLevelChanged="(a)=>{
var log=Plc?.Logger??Logger;
log.LogLevel=a;
}" LogPath=@LogPath HeaderText=@HeaderText></LogConsole>
        }
    </div>
</div>






